package com.outsource.framework.controller;

import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.outsource.framework.domain.Tcolumnse;
import com.outsource.framework.model.services.TcolumnseService;
import com.outsource.framework.util.common.Response;

@Controller
public class ColumnseContrller {

	@Autowired
	TcolumnseService service;
	
	@Autowired
	MessageSource messageSource;
	
	/**
	 * get Columns list
	 * @param usermobile
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/WoWebColumns",method = {RequestMethod.GET,RequestMethod.POST})
	public @ResponseBody Map<String, Object> WoWebColumns(
			@RequestParam("usermobile")String usermobile,
			HttpServletRequest request){
		String responseCode = getMessages("lable.code.success");
		String responseMessages = getMessages("lable.success");
		List<Tcolumnse> responseEntry = service.getByAll();
		String version = "1";
		if(responseEntry!=null&&responseEntry.size()>0){
			for (Iterator iterator = responseEntry.iterator(); iterator
					.hasNext();) {
				Tcolumnse tcolumnse = (Tcolumnse) iterator.next();
				version = String.valueOf(tcolumnse.getVersion());
			}
		}
		Response response = new Response();
		Map<String, Object> responsemap = response.getResponse_(responseCode, responseMessages, version, responseEntry);
		return responsemap;
	}
	
	/**
	 * get zh.properties content
	 * @param code
	 * @return
	 */
	public String getMessages(String code){
		return messageSource.getMessage(code, null,Locale.SIMPLIFIED_CHINESE);
	}
}
